package cn.com.ejiakanghu.dto;


import com.alibaba.fastjson.JSONArray;
import org.linlinjava.litemall.db.domain.AgedmallChargeTemplateLeasePeriod;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wj
 * @date 2022/2/16 16:09
 */
public class GoodsLeaseRuleInfo {

    private List<GoodsLeaseRules> rules;

    private Long ruleId;

    private String remark;

    private Integer minDays;

    private String type;

    private BigDecimal maxFee;

    public Integer getMinDays() {
        return minDays;
    }

    public void setMinDays(Integer minDays) {
        this.minDays = minDays;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public BigDecimal getMaxFee() {
        return maxFee;
    }

    public void setMaxFee(BigDecimal maxFee) {
        this.maxFee = maxFee;
    }

    public List<GoodsLeaseRules> getRules() {
        return rules;
    }

    public void setRules(List<GoodsLeaseRules> rules) {
        this.rules = rules;
    }

    public Long getRuleId() {
        return ruleId;
    }

    public void setRuleId(Long ruleId) {
        this.ruleId = ruleId;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }


    public GoodsLeaseRuleInfo() {
    }


    public GoodsLeaseRuleInfo(List<GoodsLeaseRules> rules, Long ruleId, String remark) {
        this.rules = rules;
        this.ruleId = ruleId;
        this.remark = remark;
    }

    public List<GoodsLeaseRules> getGoodsLeaseRules(String rules,Integer end,BigDecimal price){
        List<GoodsLeaseRules> goodsLeaseRulesList=new ArrayList<>();

        List<ChargeLadderPrice> chargeLadderPrices = JSONArray.parseArray(rules, ChargeLadderPrice.class);
        //起租期需要加入进去
        GoodsLeaseRules firstRules=new GoodsLeaseRules();
        firstRules.setBegin(0);
        firstRules.setEnd(end);
        firstRules.setPrice(price);
        goodsLeaseRulesList.add(firstRules);
        for (int i = 0; i < chargeLadderPrices.size(); i++) {
            GoodsLeaseRules goodsLeaseRules=new GoodsLeaseRules(chargeLadderPrices.get(i));
            goodsLeaseRulesList.add(goodsLeaseRules);
        }
        return goodsLeaseRulesList;
    }

    public GoodsLeaseRuleInfo(AgedmallChargeTemplateLeasePeriod leasePeriod) {
        this.rules = getGoodsLeaseRules(leasePeriod.getLadderPrice(),leasePeriod.getBaseDay(),leasePeriod.getBasePrice());
        this.ruleId = leasePeriod.getId();
        this.remark = leasePeriod.getBaseDay()+"天起租，不满"+leasePeriod.getBaseDay()+"天，按"+leasePeriod.getBaseDay()+"天结算";
    }
}
